<?php

require_once(WSB_MODULES_PATH .'sherpa/forms/NewsletterRegistration.php');

class Sherpa_NewsletterRegistrationController extends WSB_Xtension_Extension
{

	/**
	 * @return string
	 */
	public function renderForBackend()
	{
		return get_class($this);
	}

	/**
	 * Index Action
	 */
	public function indexAction()
	{
		$this->initTranslate();
		$request = $this->getRequest();
		$form = new Sherpa_Form_NewsletterRegistration();
		if($request->isPost() && $form->isValid($request->getPost())) {
			$email = $form->getValue('email');
			$client = new Zend_Http_Client('http://sherpaoutdoor.ch/newsmailer/subscribeHttp.php');
			$client->setParameterGet('email', $email);
			$response = $client->request();
			if($response->isSuccessful()) {
				$this->renderView('newsletter_registration/success.phtml');
			} else {
				$this->renderView('newsletter_registration/error.phtml');
			}
		} else {
			$form->setView($this->getView());
			$this->assignToView('form', $form);
			$this->renderView('newsletter_registration/index.phtml');
		}
	}

}